package com.superhero.common.utils;

import com.superhero.common.pojo.entity.UserHealthInfo;

import javax.xml.crypto.Data;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class StaticsUtil {


    public static List getPre7Days(){
        Calendar c = Calendar.getInstance();
        DateFormat format = new SimpleDateFormat("yyyy/MM/dd");
        List<String> sevenDayList = new ArrayList<>();
        c.setTime(new Date());

        // 过去七天
        c.add(Calendar.DATE, - 6);
        Date first = c.getTime(); // 过去7天中的第一天
        sevenDayList.add(format.format(first));
        for (int i = 0; i < 6; i++) {
            c.add(Calendar.DATE, 1);
            Date day = c.getTime();
            sevenDayList.add(format.format(day));
        }

        return sevenDayList;
    }

    public static List<Integer> get3Totals(List<UserHealthInfo> list){
        int totalHousehold = 0;
        int totalConfirmed = 0;
        int totalSuspected = 0;
        for (UserHealthInfo uhInfo : list) {
            if (uhInfo.getPersonType() != 3) {
                totalHousehold++;
                Integer symptoms = uhInfo.getSymptomsWithin14day();
                Integer observation = uhInfo.getIsolationObservation();
                Integer normal = uhInfo.getNormalTemperature();
                if (uhInfo.getConfirmed() == 1) {
                    totalConfirmed++;
                } else {
                    if (normal == 1 && symptoms + observation == 0) {
                        // 正常
                    } else totalSuspected++;
                }
            }
        }
        ArrayList<Integer> totals = new ArrayList<>();
        totals.add(totalHousehold);
        totals.add(totalConfirmed);
        totals.add(totalSuspected);

        return totals;
    }
}
